package com.qianyu.project.service.handler;

import com.alibaba.fastjson.JSON;
import com.qianyu.project.core.annotation.FlowHandler;
import com.qianyu.project.core.bean.FormAudit;
import com.qianyu.project.core.context.handler.FlowFinishedHandler;
import com.qianyu.project.entity.ContractReceipt;
import com.qianyu.project.mapper.ContractReceiptMapper;
import com.qianyu.project.service.IContractReceiptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@FlowHandler("contract_receipt")
public class ContractReceiptPostProcessor implements FlowFinishedHandler {
    @Autowired
    private IContractReceiptService contractReceiptService;

    @Override
    public void postAllowHandle(String jsonForm, FormAudit formAudit) {
        this.commonUpdate(jsonForm, formAudit, 3);
    }

    @Override
    public void postRefuseHandle(String jsonForm, FormAudit formAudit) {
        this.commonUpdate(jsonForm, formAudit, 2);
    }

    private void commonUpdate(String jsonForm, FormAudit formAudit, Integer approveStatus){
        ContractReceipt contractReceipt = JSON.parseObject(jsonForm, ContractReceipt.class);
        contractReceipt.setApproveStatus(approveStatus);
        contractReceiptService.updateById(contractReceipt);
    }
}
